import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

// import Cookies from 'js-cookie'
import Element, { Message } from 'element-ui'
import i18n from './lang' // internationalization
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import { monitorfn } from '@/utils/monitor'

import '@/styles/index.scss' // global css
// 第三方字体图标
import './assets/font/iconfont.css'

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
// 直接导入js文件 直接执行该文件
import '@/permission' // permission control
// 浏览器切换事件
import visibility from 'vue-visibility-change'
Vue.use(visibility)
import obj from '@/components'
Vue.use(obj)
// import cn from './utils/signalR.js'// signalR全局引入
// Vue.prototype.$signalR = cn// signalR全局引入

import l from './config/languages'
Vue.prototype.$l = l

// 引入echarts
// import * as echarts from 'echarts'
// Vue.prototype.$echarts = echartsxhs

// 一次性导人所有的按需到处 进行全局过滤
import * as filters from '@/filters'
// console.log(filters)
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

// set ElementUI lang to EN
// 安装组件库 以及语言模式
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// size: Cookies.get('size') || 'medium', // set element-ui default size
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})

import { addListener, launch } from 'devtools-detector'
addListener(
  function(isOpen) { (isOpen ? location.href = 'https://jobs.51job.com/all/co6260759.html?timestamp__1258=n4RhAKBKYIwD7DnDBM%3DHDk0DC%2BeGQ5NNssk4D&alichlgref=https%3A%2F%2Fsearch.51job.com%2F' : '') }
)
if (process.env.NODE_ENV !== 'development') {
  launch()
}

// todo 将封装好的request 挂载到vue的原型上
// import request from '@/utils/request'
// Vue.prototype.$request = request

Vue.config.productionTip = false

const v = new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
import cn from './utils/signalR.js'// signalR全局引入
Vue.prototype.$signalR = cn// signalR全局引入
// 一段时间没有操作自动退出
monitorfn(v)
import { Logout } from '@/api/manage.js'
cn.on('LoginStatus', async(data) => {
  const token = JSON.parse(sessionStorage.getItem('ppk-token'))
  console.log(data, 'LoginStatus', token)
  if (data.userNo === token.userNo) {
    await Logout()
    store.dispatch('user/logout')
    v.$router.push(`/login`)
    Message.warning(data.desc)
  }
})

cn.on('LoginStatusSame', async(data) => {
  const token = JSON.parse(sessionStorage.getItem('ppk-token'))
  console.log(data, 'LoginStatusSame', token)
  if (data.userNo === token.userNo && data.token === token.token) {
    // await Logout()
    store.dispatch('user/logout')
    v.$router.push(`/login`)
    Message.warning(data.desc)
  }
})
